<!DOCTYPE html>
<html lang="en">

    <head>

        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <meta name="description" content="">
        <meta name="author" content="">

        <title>Kura's Hardware Shop</title>

        <!-- Bootstrap Core CSS -->
        <link href="css/bootstrap.min.css" rel="stylesheet">

        <!-- MetisMenu CSS -->
        <link href="css/plugins/metisMenu/metisMenu.min.css" rel="stylesheet">

        <!-- Custom CSS -->
        <link href="css/sb-admin-2.css" rel="stylesheet">

        <!-- Custom Fonts -->
        <link href="font-awesome-4.1.0/css/font-awesome.min.css" rel="stylesheet" type="text/css">

        <!-- Bootstrap Core CSS -->
        <link href="css/bootstrap.min.css" rel="stylesheet">

        <!-- MetisMenu CSS -->
        <link href="css/plugins/metisMenu/metisMenu.min.css" rel="stylesheet">

        <!-- DataTables CSS -->
        <link href="css/plugins/dataTables.bootstrap.css" rel="stylesheet">

        <!-- Custom CSS -->
        <link href="css/sb-admin-2.css" rel="stylesheet">

        <!-- Custom Fonts -->
        <link href="font-awesome-4.1.0/css/font-awesome.min.css" rel="stylesheet" type="text/css">

        <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
        <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
        <!--[if lt IE 9]>
            <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
            <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
        <![endif]-->

    </head>

    <body>
        <?php
        session_start();
        if (!isset($_SESSION['role'])) {
            header("Location: login.php");
        }
        include('script/userScript.php');
        ?>
        <div id="wrapper">

            <!-- Navigation -->
            <nav class="navbar navbar-default navbar-static-top" role="navigation" style="margin-bottom: 0">
                <div class="navbar-header">
                    <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
                        <span class="sr-only">Toggle navigation</span>
                        <span class="icon-bar"></span>
                        <span class="icon-bar"></span>
                        <span class="icon-bar"></span>
                    </button>
                    <a class="navbar-brand" href="index.html">Xin chào <?php echo $_SESSION['name'] ?></a> <!-- get User late -->
                </div>
                <!-- /.navbar-header -->

                <ul class="nav navbar-top-links navbar-right">

                    <li class="dropdown">
                        <a class="dropdown-toggle" data-toggle="dropdown" href="#">
                            <i class="fa fa-user fa-fw"></i>  <i class="fa fa-caret-down"></i>
                        </a>
                        <ul class="dropdown-menu dropdown-user">
                            <li><a href="info.php"><i class="fa fa-user fa-fw"></i> Thông tin cá nhân</a>
                            </li>

                            <li class="divider"></li>
                            <li><a href="script/logoutScript.php"><i class="fa fa-sign-out fa-fw"></i> Đăng xuất</a>
                            </li>
                        </ul>
                        <!-- /.dropdown-user -->
                    </li>
                    <!-- /.dropdown -->
                </ul>
                <!-- /.navbar-top-links -->

               <div class="navbar-default sidebar" role="navigation">
                    <div class="sidebar-nav navbar-collapse">
                        <ul class="nav" id="side-menu">
                            <?php
                            if ($_SESSION['role'] == 1) {
                                ?>
                                <li>
                                    <a class="active" href="statistic.php"><i class="fa fa-bar-chart-o fa"></i> &nbspThống kê<span class="fa arrow"></span></a>
                                    <ul class="nav nav-second-level">
                                        <li>
                                            <a href="statistic.php">Doanh thu</a>
                                        </li>
                                    </ul>
                                </li>

                                <li>
                                    <a href="users.php"><i class="fa fa-user fa-fw"></i> Quản lí nhân viên</a>

                                    <!-- /.nav-second-level -->
                                </li>
                                <?php
                            }
                            ?>
                            <li>
                                <a href="customers.php"><i class="fa fa-wrench fa-fw"></i>&nbsp;Quản lí khách hàng</a>

                                <!-- /.nav-second-level -->
                            </li>
                            <li>
                                <a href="#"><i class="fa fa-shopping-cart fa-fw"></i> Quản lí sản phẩm<span class="fa arrow"></span></a>
                                <ul class="nav nav-second-level">
                                    <li>
                                        <a href="categories.php">Danh mục</a>
                                    </li>
                                    <li>
                                        <a href="manufacturers.php">Nhà sản xuất</a>
                                    </li>                                    
                                    <li>
                                        <a href="products.php">Sản phẩm</a>
                                    </li>
                                </ul>
                            </li>
                            <li>

                                <a href="#"><i class="fa fa-edit fa-fw"></i> Quản lí đơn hàng<span class="fa arrow"></span></a>
                                <ul class="nav nav-second-level">
                                    <li>
                                        <a href="orders_in.php">Hóa đơn nhập</a>
                                    </li>
                                    <li>
                                        <a href="orders_out.php">Hóa đơn xuất</a>
                                    </li>

                                </ul>
                            </li>
                        </ul>
                        <!-- /.nav-second-level -->
                    </div>
                    <!-- /.sidebar-collapse -->
                </div>
                <!-- /.navbar-static-side -->
            </nav>



            <!-- Page Content -->
            <div id="page-wrapper">

                <div class="row">
                    <?php
                    if (isset($_GET['status'])) {
                        if ($_GET['status'] == "createFail") {
                            echo "<div class='alert alert-danger' id='danger-alert'>
                                        Mật khẩu nhập lại không đúng!
                                  </div>";
                        }else if ($_GET['status'] == "resetSuccess") {
                            echo "<div class='alert alert-success' id='danger-alert'>
                                        Khôi phục mật khẩu mặc định thành công!!!
                                  </div>";
                        }else if ($_GET['status'] == "updateSuccess") {
                            echo "<div class='alert alert-success' id='danger-alert'>
                                        Cập nhật thông tin thành công!!!
                                  </div>";
                        }else{
                            echo "<div class='alert alert-success' id='danger-alert'>
                                        Tạo nhân viên thành công!
                                  </div>";
                        }
                    }
                    ?>
                </div>
                <div class="row">
                    <ul class="nav nav-tabs" role="tablist">
                        <li><a href="#new" role="tab" data-toggle="tab">Thêm mới</a></li>
                        <li class="active"><a href="#list" role="tab" data-toggle="tab">Danh sách nhân viên</a></li>
                    </ul>
                </div>
                <div class="row">
                    <div class="panel panel-default">
                        <div class="panel-body">
                            <!-- /.col-lg-12 -->
                            <div class="tab-content"> 
                                <div id="new" class="tab-pane">
                                    <form method="POST" action="script/userScript.php">
                                        <div class="row">
                                            <div class="form-group col-lg-6" >
                                                <label>Họ tên</label>
                                                <input type="text" name="name" id="name"  class="form-control">
                                            </div>
                                            <div class="form-group col-lg-6">
                                                <label>Email</label>
                                                <input type="text" name="email" id="email" class="form-control">
                                            </div>
                                        </div>

                                        <div class="row">
                                            <div class="form-group col-lg-6">
                                                <label>Mật khẩu</label>
                                                <input pattern=".{6,}" required title="Mật khẩu ít nhất là 6 kí tự" type="password" name="pass" id="pass" class="form-control">
                                            </div>
                                            <div class="form-group col-lg-6">
                                                <label>Xác nhận mật khẩu</label>
                                                <input type="password" name="rePass" id="rePass" class="form-control">
                                            </div>
                                        </div>

                                        <div class="row">
                                            <div class="form-group col-lg-6">
                                                <label>Địa chỉ</label>
                                                <input type="text" name="add" id="add" class="form-control">
                                            </div>
                                            <div class="form-group col-lg-6">
                                                <label>Số điện thoại</label>
                                                <input type="text" name="phone" id="phone" class="form-control">
                                            </div>
                                        </div>

                                        <div class="row">
                                            <div class="form-group col-lg-6">
                                                <label>Chứng minh nhân dân</label>
                                                <input pattern=".{9}" required title="CMND phải có 9 số" type="number" name="idnum" id="idnum" class="form-control">
                                            </div>
                                            <div class="form-group col-lg-6">
                                                <label>Ngày sinh</label>
                                                <input type="text" name="birth" id="birth" class="form-control">
                                            </div>
                                        </div>

                                        <div class="row">
                                            <div class="form-group col-lg-6">
                                                <label>Giới tính</label>
                                                <select id="gender" name="gender">
                                                    <option>Nam</option>
                                                    <option>Nữ</option>
                                                </select>
                                            </div>
                                            <div class="form-group col-lg-6">
                                                <label>Phân quyền</label>
                                                <select id="role" name="role">
                                                    <option>Admin</option>
                                                    <option>Nhân viên</option>
                                                </select>
                                            </div>
                                        </div>

                                        <div class="modal-footer">
                                            
                                            <input class='btn btn-primary' type="submit" name="option" value="Thêm mới">                                           
                                        </div>
                                    </form>
                                   
                                </div>
                                <div id="list" class="tab-pane active">
                                    <?php printTable(); ?>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <hr>
        </div>
        <!-- /#wrapper -->

        <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
                        <h4 class="modal-title" id="myModalLabel">Cập nhật</h4>
                    </div>
                    <div class="modal-body">
                        <form method="POST" action="script/userScript.php">
                            <div class="form-group">
                                <label>Họ tên</label>
                                <input type="text" name="name" id="name_val"  class="form-control">
                            </div>

                            <div class="form-group">
                                <label>Email</label>
                                <input type="text" name="email" id="email_val" class="form-control">
                            </div>

                            

                            <div class="form-group">
                                <label>Địa chỉ</label>
                                <input type="text" name="add" id="add_val" class="form-control">
                            </div>

                            <div class="form-group">
                                <label>Số điện thoại</label>
                                <input type="text" name="phone" id="phone_val" class="form-control">
                            </div>

                            <div class="form-group">
                                <label>Giới tính</label>
                                <select id="gender_val" name="gender">
                                    <option>Nam</option>
                                    <option>Nữ</option>
                                </select>
                            </div>

                            <div class="form-group">
                                <label>Ngày sinh</label>
                                <input type="text" name="birth" id="birth_val" class="form-control">
                            </div>

                            <div class="form-group">
                                <label>Chứng minh nhân dân</label>
                                <input type="text" name="idnum" id="idnum_val" class="form-control">
                            </div>

                            <div class="form-group">
                                <label>Phân quyền</label>
                                <select id="role_val" name="role">
                                    <option>Admin</option>
                                    <option>Nhân viên</option>
                                </select>
                            </div>

                            <div class="modal-footer">
                                <input class='btn btn-primary' type="submit" name="option" value="Cập nhật">
                            </div>
                        </form>
                    </div>                    
                </div>
            </div>
        </div>

        <!-- jQuery Version 1.11.0 -->
        <script src="js/jquery-1.11.0.js"></script>

        <!-- Bootstrap Core JavaScript -->
        <script src="js/bootstrap.min.js"></script>

        <!-- Metis Menu Plugin JavaScript -->
        <script src="js/plugins/metisMenu/metisMenu.min.js"></script>

        <!-- Custom Theme JavaScript -->
        <script src="js/sb-admin-2.js"></script>

        <!-- DataTables JavaScript -->
        <script src="js/plugins/dataTables/jquery.dataTables.js"></script>
        <script src="js/plugins/dataTables/dataTables.bootstrap.js"></script>

        <!-- Custom Theme JavaScript -->


        <!-- Page-Level Demo Scripts - Tables - Use for reference -->
        <script>
            $(document).ready(function() { //Đổ dữ liệu từ bảng vào các thẻ input
                $('#dataTables-example').dataTable();
            });
        </script>
        <script>
            $("button").click(function() {
                if($(this).attr("value") == "edit" )  {
                    var gEmail = $(this).closest('tr').find('td:eq(1)').text();
                    $('#email_val').val(gEmail);
                    var gName = $(this).closest('tr').find('td:eq(0)').text(); 
                    $('#name_val').val(gName);
                    var gAdd = $(this).closest('tr').find('td:eq(2)').text(); 
                    $('#add_val').val(gAdd);
                    var gPhone = $(this).closest('tr').find('td:eq(3)').text(); 
                    $('#phone_val').val(gPhone);
                    var gGender = $(this).closest('tr').find('td:eq(4)').text();
                    $('#gender_val').val(gGender);
                    var gBirth = $(this).closest('tr').find('td:eq(5)').text();  
                    $('#birth_val').val(gBirth);
                    //var gPass = $(this).closest('tr').find('td:eq(2)').text();  
                    //$('#pass_val').val(gPass);
                    var gIdNum = $(this).closest('tr').find('td:eq(6)').text();  
                    $('#idnum_val').val(gIdNum);
                    var gRole = $(this).closest('tr').find('td:eq(7)').text();  
                    $('#role_val').val(gRole);
                }
            });
        </script>
        <script>
            $("#danger-alert").fadeTo(2000, 500).slideUp(500, function() {
                $("#danger-alert").alert('close');
            });
        </script>

    </body>

</html>
